package cn.heygod.graywhale.runtime.task.def;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @className: TaskDefineManager
 * @author: Simon
 * @description: TODO
 * @date: 2023/11/23 1:31
 * @version: 1.0
 */
@Component
public class TaskDefineManager {

    private ConcurrentMap<String,TaskFlowDef> flowDefMap = new ConcurrentHashMap();

    public void addFlow(TaskFlowDef flowDef){
        flowDefMap.put(flowDef.getId(),flowDef);
    }

    public void removeFlow(String flowDefId){
        flowDefMap.remove(flowDefId );
    }

    public void refreshFlow(TaskFlowDef flowDef){
        //TODO 运行中的是否处理：
        flowDefMap.replace(flowDef.getId(),flowDef);
    }

    public void removeAll(){
        flowDefMap.clear();
    }

    public TaskFlowDef getFlow(String flowDefId){
        return flowDefMap.get(flowDefId);
    }
}
